//
//  UILabel+FormattedText.m
//  UILabel+FormattedText
//
//  Created by Joao Costa on 3/1/13.
//  Copyright (c) 2013 none. All rights reserved.
//

#import "UILabel+FormattedText.h"

@implementation UILabel (FormattedText)
/*
 +(void)load
 {
 Method m1 = class_getInstanceMethod(self, @selector(setTextColor:));
 Method m2 = class_getInstanceMethod(self, @selector(theNewsetTextColor:));
 method_exchangeImplementations(m1, m2);
 }
 */

- (void)setTextColor:(UIColor *)textColor range:(NSRange)range
{
    if(!SYSTEM_VERSION_LESS_THAN(@"6.0")){
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: self.attributedText];
        [text addAttribute: NSForegroundColorAttributeName
                     value: textColor
                     range: range];
        
        [self setAttributedText: text];
    }else{
         DLog(@"ios6以下的系统不支持此方法");
    }
}

- (void)setFont:(UIFont *)font range:(NSRange)range
{
    if(!SYSTEM_VERSION_LESS_THAN(@"6.0")){
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: self.attributedText];
    [text addAttribute: NSFontAttributeName
                 value: font
                 range: range];
    [self setAttributedText: text];
    }else{
        DLog(@"ios6以下的系统不支持此方法");
    }
}

@end
